package com.example.anni.zhuzhoujia.tianya12345;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextPaint;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.anni.zhuzhoujia.R;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangshengwen2016 on 2016/6/4.
 * 查看我发起的活动详情
 */
public class CityMyDetails extends AppCompatActivity {
    public String id;
    public String activityParticipateIns1;
    public JSONArray activityParticipateIns;
    public Button participate;
    private List<Map<String, Object>> list;
    public StationaryGridview grid_item;//GridView
    private int width;
    private int height;
    private String images;
    private String[] tabs = {"加载图片", "不加载图片", "隐藏图片", "显示图片"};
    private List<Map<String, Object>> list_tab;

    //选项卡
    private void tabData() {
        list_tab = new ArrayList<>();
        for (int i = 0; i < tabs.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("tabs", tabs[i]);
            list_tab.add(map);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.city_details);
        tabData();//选项卡数据
        //获取屏幕高度和宽度
        WindowManager wm = this.getWindowManager();
        width = wm.getDefaultDisplay().getWidth();
        height = wm.getDefaultDisplay().getHeight();
        LinearLayout city_return = (LinearLayout) findViewById(R.id.city_return);//返回图片
        final LinearLayout participants = (LinearLayout) findViewById(R.id.participants);//参与线性布局
        city_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //调用登录接口
        RequestParams params1 = new RequestParams("http://tr.zzapi.gson.cn/api/user/login");
        params1.addBodyParameter("userName", "测试");
        params1.addBodyParameter("password", "666666");
        x.http().post(params1, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String s) {
            }

            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
        participate = (Button) findViewById(R.id.participate);
        Toolbar t = (Toolbar) findViewById(R.id.tl_custom);
        //获取外面传过来的id
        Intent intent = getIntent();
        id = intent.getStringExtra("id");
        //获取活动详情
        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/activity/detail?cid=" + id);
        x.http().get(params, new Callback.CommonCallback<String>() {
                    @Override
                    public void onSuccess(String s) {
                        com.alibaba.fastjson.JSONObject json1 = JSON.parseObject(s);
                        String data = json1.getString("data");
                        JSONObject obj = JSON.parseObject(data);
                        String title = obj.getString("title");//标题
                        String startLine = obj.getString("startLine");//开始时间
                        String endLine = obj.getString("endLine");//结束时间
                        String address = obj.getString("address");//地址
                        String area = obj.getString("area");//活动区域
                        if (area.equals("SF")) {
                            area = "石峰区";
                        }
                        if (area.equals("YL")) {
                            area = "炎陵县";
                        }
                        if (area.equals("YLSFFQ")) {
                            area = "云龙示范区";
                        }
                        if (area.equals("ZZX")) {
                            area = "株洲县";
                        }
                        if (area.equals("YX")) {
                            area = "攸县";
                        }
                        if (area.equals("TY")) {
                            area = "天元区";
                        }
                        if (area.equals("LL")) {
                            area = "醴陵市";
                        }
                        if (area.equals("LS")) {
                            area = "芦淞区";
                        }
                        if (area.equals("HT")) {
                            area = "荷塘区";
                        }
                        if (area.equals("CL")) {
                            area = "茶陵县";
                        }
                        images = obj.getString("images");//活动图片
                        //读取数据
                        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(CityMyDetails.this);
                        String LoadImage = sp.getString("LoadImage", "");
                        if (LoadImage.equals("no")) {
                            images = "";
                        }
                        String dateline = obj.getString("dateline");//活动创建时间
                        final String partIn = obj.getString("partIn");//当前参加人数
                        final String peoples = obj.getString("peoples");//人数上限
                        String description = obj.getString("description");//活动摘要

                        activityParticipateIns1 = obj.getString("activityParticipateIns");
                        String user = obj.getString("user");//用户
                        JSONObject obj1 = JSON.parseObject(user);
                        String avatar = obj1.getString("avatar");//头像
                        String nickName = obj1.getString("nickName");//昵称
                        String gender = obj1.getString("gender");//性别

                        TextView tv_title = (TextView) findViewById(R.id.title);
                        tv_title.setText(title);
                        TextView tv_startLine = (TextView) findViewById(R.id.startLine);
                        tv_startLine.setText("开始时间：" + startLine.substring(0, 10));
                        TextView tv_endLine = (TextView) findViewById(R.id.endLine);
                        tv_endLine.setText("结束时间：" + endLine.substring(0, 10));
                        TextView tv_address = (TextView) findViewById(R.id.address);
                        tv_address.setText("活动地点：" + address);
                        TextView tv_area = (TextView) findViewById(R.id.area);
                        tv_area.setText("活动区域：" + area);
                        TextView tv_current_number = (TextView) findViewById(R.id.current_number);
                        tv_current_number.setText("已报名：" + partIn);
                        TextView tv_max_number = (TextView) findViewById(R.id.max_number);
                        tv_max_number.setText("人数上限：" + peoples);
                        TextView tv_description = (TextView) findViewById(R.id.description);
                        tv_description.setText(description);
                        if (images.length() == 0) {
                            LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                            linear_img.setVisibility(View.GONE);
                        } else {
                            LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                            linear_img.setVisibility(View.VISIBLE);
                        }

                        //把图片分割成数组
                        final String[] array_img = images.split(",");
                        grid_item = (StationaryGridview) findViewById(R.id.gv);
                        ImageView iv_img = (ImageView) findViewById(R.id.iv_img);
                        LinearLayout line_iv_img = (LinearLayout) findViewById(R.id.line_iv_img);
                        ImageView iv_img1 = (ImageView) findViewById(R.id.iv_img1);
                        ImageView iv_img2 = (ImageView) findViewById(R.id.iv_img2);
                        //如果只有一张图片则iv_img组件显示，其他隐藏
                        if (array_img.length == 0) {

                        } else if (array_img.length == 1) {
                            iv_img.setVisibility(View.VISIBLE);
                            grid_item.setVisibility(View.GONE);
                            line_iv_img.setVisibility(View.GONE);
                            ImageOptions options3 = new ImageOptions.Builder()
                                    .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                                    .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                                    .build();
                            x.image().bind(iv_img, "http://tr.zzapi.gson.cn/" + images, options3);
                            //查看大图
                            iv_img.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(CityMyDetails.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", 0);
                                    startActivity(intent);
                                }
                            });
                        } else if (array_img.length == 2) {//如果只有两张图片则line_iv_img组件显示，其他隐藏
                            iv_img.setVisibility(View.GONE);
                            grid_item.setVisibility(View.GONE);
                            line_iv_img.setVisibility(View.VISIBLE);
                            ImageOptions options3 = new ImageOptions.Builder()
                                    .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                                    .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                                    .build();
                            x.image().bind(iv_img1, "http://tr.zzapi.gson.cn/" + array_img[0], options3);
                            x.image().bind(iv_img2, "http://tr.zzapi.gson.cn/" + array_img[1], options3);
                            //查看大图
                            iv_img1.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(CityMyDetails.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", 0);
                                    startActivity(intent);
                                }
                            });
                            //查看大图
                            iv_img2.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(CityMyDetails.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", 1);
                                    startActivity(intent);
                                }
                            });
                        } else {
                            iv_img.setVisibility(View.GONE);
                            line_iv_img.setVisibility(View.GONE);
                            grid_item.setVisibility(View.VISIBLE);
                            //活动图片
                            //图片适配器
                            class ImgAdapter extends BaseAdapter {
                                public ImgAdapter() {
                                    list = new ArrayList<>();
                                    for (int i = 0; i < array_img.length; i++) {
                                        Map<String, Object> map = new HashMap<>();
                                        map.put("img", array_img[i]);
                                        list.add(map);
                                    }
                                }

                                public int getCount() {
                                    return list.size();
                                }

                                public Object getItem(int position) {
                                    return list.get(position);
                                }

                                public long getItemId(int position) {
                                    return 0;
                                }

                                public View getView(int position, View convertView, ViewGroup parent) {
                                    final ViewHolder viewHolder;
                                    if (convertView == null) {
                                        convertView = LayoutInflater.from(CityMyDetails.this).inflate(R.layout.broke_img, null);
                                        viewHolder = new ViewHolder();
                                        viewHolder.Iv_img = (ImageView) convertView.findViewById(R.id.broke_img);
                                        convertView.setTag(viewHolder);
                                    } else {
                                        viewHolder = (ViewHolder) convertView.getTag();
                                    }
                                    ImageOptions options3 = new ImageOptions.Builder()
                                            .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                                            .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                                            .build();
                                    x.image().bind(viewHolder.Iv_img, "http://tr.zzapi.gson.cn/" + list.get(position).get("img"), options3);
                                    return convertView;
                                }

                                class ViewHolder {
                                    public ImageView Iv_img;
                                }
                            }
                            //添加适配器
                            grid_item.setAdapter(new ImgAdapter());
                            //查看大图
                            grid_item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                    Intent intent = new Intent(CityMyDetails.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", position);
                                    startActivity(intent);
                                }
                            });
                        }
                        //设置按钮的监听器
                        ImageView bt = (ImageView) findViewById(R.id.cs);
                        final String finalImages1 = images;
                        bt.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(CityMyDetails.this);
                                builder.setTitle("选择");
                                final BaseAdapter adapter = new tabAdapter();
                                //单击事件
                                builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        Map<String, Object> map = (Map<String, Object>) adapter.getItem(which);
                                        //加载图片
                                        if (which == 0) {
                                            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(CityMyDetails.this);
                                            SharedPreferences.Editor editor = sp.edit();
                                            editor.putString("LoadImage", "yes");
                                            editor.commit();
                                        }
                                        //不加载图片
                                        if (which == 1) {
                                            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(CityMyDetails.this);
                                            SharedPreferences.Editor editor = sp.edit();
                                            editor.putString("LoadImage", "no");
                                            editor.commit();
                                        }
                                        if (which == 2) {
                                            LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                                            linear_img.setVisibility(View.GONE);
                                        }
                                        if (which == 3 & finalImages1.length() != 0) {
                                            LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                                            linear_img.setVisibility(View.VISIBLE);
                                        }
                                    }
                                });
                                AlertDialog dialog = builder.create();
                                dialog.show();
                                //设置高度宽度和大小
                                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                                params.width = 500;
                                params.height = 800;
                                params.x = width - 400;
                                params.y = -(height / 2 - 580);
                                dialog.getWindow().setAttributes(params);
                                //设置动画
                                Window window = dialog.getWindow();
                                window.setWindowAnimations(R.style.dialog_anim);
                            }
                        });
                        //设置用户头像、昵称、性别图标、创建时间
                        ImageView avatar_img = (ImageView) findViewById(R.id.avatar);
                        ImageOptions options2 = new ImageOptions.Builder()
                                .setCircular(true)//设置圆形
                                .setLoadingDrawableId(R.mipmap.default_avatar)//加载过程中的等待图片
                                .setFailureDrawableId(R.mipmap.default_avatar)//加载出错显示的图片
                                .build();
                        //显示远程图片
                        x.image().bind(
                                avatar_img,
                                "http://tr.zzapi.gson.cn/" + avatar,
                                options2
                        );
                        TextView tv_nickName = (TextView) findViewById(R.id.nickName);
                        tv_nickName.setText("" + nickName);
                        ImageView gender_img = (ImageView) findViewById(R.id.gender);
                        if (gender.equals("BOY")) {
                            gender_img.setImageResource(R.mipmap.boy);
                        } else {
                            gender_img.setImageResource(R.mipmap.girl);
                        }
                        //活动创建时间
                        TextView dateline_text1 = (TextView) findViewById(R.id.dateline1);
                        dateline_text1.setText(dateline.substring(0, 10));
                        TextView dateline_text2 = (TextView) findViewById(R.id.dateline2);
                        dateline_text2.setText(dateline.substring(10));

                        //如果参与人数为0则显示暂无参与用户
                        if (partIn.equals("0")) {
                            TextView partIn0 = (TextView) findViewById(R.id.partIn0);
                            partIn0.setVisibility(View.VISIBLE);
                        }
                        //参与人数
                        activityParticipateIns = obj.getJSONArray("activityParticipateIns");
                        for (int i = 0; i < activityParticipateIns.size(); i++) {
                            JSONObject obj2 = activityParticipateIns.getJSONObject(i);
                            String content2 = obj2.getString("content");
                            String telephone = obj2.getString("telephone");//用户电话
                            String dateline2 = obj2.getString("dateline");
                            String id2 = obj2.getString("id");
                            String lastUpdate2 = obj2.getString("lastUpdate");
                            String telephone2 = obj2.getString("telephone");
                            String user2 = obj2.getString("user");
                            JSONObject obj3 = JSON.parseObject(user2);
                            String avatar3 = obj3.getString("avatar");//头像
                            String nickName3 = obj3.getString("nickName");//昵称
                            String gender3 = obj3.getString("gender");//性别
                            String lastUpdate3 = obj3.getString("lastUpdate");//参与时间

                            //设置参与区
                            if (i != 0) {
                                //分割线
                                TextView text = new TextView(CityMyDetails.this);
                                LinearLayout.LayoutParams lp11 = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT,
                                        2
                                );
                                lp11.setMargins(10, 10, 10, 10);
                                text.setLayoutParams(lp11);
                                text.setBackgroundColor(0xffaaaaaa);
                                participants.addView(text);
                            }
                            //用户信息
                            LinearLayout u_linear1 = new LinearLayout(CityMyDetails.this);
                            LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            lp1.setMargins(10, 10, 10, 10);
                            u_linear1.setLayoutParams(lp1);
                            u_linear1.setOrientation(LinearLayout.HORIZONTAL);
                            participants.addView(u_linear1);

                            //参与用户头像
                            ImageView u_iv_avatar = new ImageView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(130, 130);
                            lp2.gravity = Gravity.CENTER_VERTICAL;
                            u_iv_avatar.setLayoutParams(lp2);
                            u_linear1.addView(u_iv_avatar);
                            ImageOptions options3 = new ImageOptions.Builder()
                                    .setCircular(true)//设置圆形
                                    .setLoadingDrawableId(R.mipmap.default_avatar)//加载过程中的等待图片
                                    .setFailureDrawableId(R.mipmap.default_avatar)//加载出错显示的图片
                                    .build();
                            x.image().bind(u_iv_avatar, "http://tr.zzapi.gson.cn/" + avatar3, options3);
                            //昵称、性别、第几楼、时间
                            LinearLayout u_linear2 = new LinearLayout(CityMyDetails.this);
                            LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            lp3.setMargins(20, 10, 10, 10);
                            lp3.gravity = Gravity.CENTER_VERTICAL;
                            u_linear2.setLayoutParams(lp3);
                            u_linear2.setOrientation(LinearLayout.VERTICAL);
                            u_linear1.addView(u_linear2);
                            //昵称、性别
                            LinearLayout u_linear3 = new LinearLayout(CityMyDetails.this);
                            LinearLayout.LayoutParams lp4 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            lp4.gravity = Gravity.CENTER_VERTICAL;
                            u_linear3.setLayoutParams(lp4);
                            u_linear3.setOrientation(LinearLayout.HORIZONTAL);
                            u_linear2.addView(u_linear3);
                            //用户昵称
                            //android:singleLine="true"超过一行末尾会显示...
                            TextView u_tv_nickname = new TextView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp5 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    1
                            );
                            u_tv_nickname.setText(nickName3);
                            u_tv_nickname.setSingleLine(true);
                            u_tv_nickname.setLayoutParams(lp5);
                            u_linear3.addView(u_tv_nickname);
                            //性别
                            ImageView u_iv_gender = new ImageView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp6 = new LinearLayout.LayoutParams(50, 50);
                            lp4.setMargins(10, 10, 10, 10);
                            lp6.gravity = Gravity.CENTER_VERTICAL;
                            u_iv_gender.setLayoutParams(lp6);
                            if (gender3.equals("BOY")) {
                                u_iv_gender.setImageResource(R.mipmap.boy);
                            } else {
                                u_iv_gender.setImageResource(R.mipmap.girl);
                            }
                            u_linear3.addView(u_iv_gender);
                            //第几楼、时间
                            LinearLayout u_linear4 = new LinearLayout(CityMyDetails.this);
                            LinearLayout.LayoutParams lp7 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            lp7.gravity = Gravity.CENTER_VERTICAL;
                            u_linear4.setLayoutParams(lp7);
                            u_linear4.setOrientation(LinearLayout.HORIZONTAL);
                            u_linear2.addView(u_linear4);
                            //第几楼
                            TextView floor = new TextView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp8 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            floor.setText((i + 1) + "楼");
                            floor.setTextColor(0xffaaaaaa);
                            floor.setTextSize(12);
                            lp8.setMargins(0, 0, 20, 0);
                            floor.setLayoutParams(lp8);
                            u_linear4.addView(floor);
                            //时间
                            TextView u_lastUpdate = new TextView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp9 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            u_lastUpdate.setText(lastUpdate2);
                            u_lastUpdate.setLayoutParams(lp9);
                            u_linear4.addView(u_lastUpdate);
                            u_lastUpdate.setTextColor(0xffaaaaaa);
                            u_lastUpdate.setTextSize(12);
                            //电话
                            TextView u_tv_telephone = new TextView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp11 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            u_tv_telephone.setText("联系电话：" + telephone);
                            u_tv_telephone.setTextColor(0xff993399);
                            TextPaint tp = u_tv_telephone.getPaint();
                            tp.setFakeBoldText(true);//粗体
                            lp11.setMargins(30, 5, 5, 15);
                            u_tv_telephone.setLayoutParams(lp11);
                            participants.addView(u_tv_telephone);
                            //内容
                            TextView u_tv_content = new TextView(CityMyDetails.this);
                            LinearLayout.LayoutParams lp10 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            u_tv_content.setText(content2);
                            u_tv_content.setTextColor(0xff000000);
                            lp10.setMargins(30, 5, 5, 15);
                            u_tv_content.setLayoutParams(lp10);
                            participants.addView(u_tv_content);
                        }
                        //获取我的同城活动
                        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/user/activity");
                        x.http().get(params, new Callback.CommonCallback<String>() {
                            @Override
                            public void onSuccess(String s) {
                                String s1 = "未参加";//设置一个变量，用来区别当前的活动我是否参与过
                                com.alibaba.fastjson.JSONObject json = JSON.parseObject(s);
                                JSONArray data = json.getJSONArray("data");
                                for (int i = 0; i < data.size(); i++) {
                                    JSONObject obj1 = data.getJSONObject(i);
                                    JSONArray participateIn = obj1.getJSONArray("participateIn");
                                    for (int j = 0; j < participateIn.size(); j++) {
                                        JSONObject obj2 = participateIn.getJSONObject(j);
                                        String details_id = obj2.getString("id");
                                        //当前活动的id与我所参与的活动的所有id进行比较，如果有相同的则给s1赋值已参加
                                        if (details_id.equals(id + "")) {
                                            s1 = "已参加";
                                            break;
                                        }
                                    }
                                }
                                int dq = Integer.parseInt(partIn);//当前人数
                                int sx = Integer.parseInt(peoples);//人数上限
                                if (s1.equals("未参加") & (dq < sx)) {
                                    //设置报名按钮的监听器,打开报名Activity，传id过去
                                    participate.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            Intent intent = new Intent(CityMyDetails.this, CityParticipate.class);
                                            intent.putExtra("id", id);
                                            startActivity(intent);
                                        }
                                    });
                                } else if (s1.equals("已参加")) {
//                                    Toast.makeText(CityDetails.this, "你已参加此活动！", Toast.LENGTH_LONG).show();
                                    participate.setText("你已参加此活动");
                                    participate.setEnabled(false);
                                    participate.setBackgroundResource(R.drawable.ysw_bt3);
                                } else {
//                                    Toast.makeText(CityDetails.this, "此活动人数已达上限！", Toast.LENGTH_LONG).show();
                                    participate.setText("此活动人数已达上限");
                                    participate.setEnabled(false);
                                    participate.setBackgroundResource(R.drawable.ysw_bt3);
                                }
                            }

                            @Override
                            public void onError(Throwable throwable, boolean b) {

                            }

                            @Override
                            public void onCancelled(CancelledException e) {

                            }

                            @Override
                            public void onFinished() {

                            }
                        });
                    }

                    @Override
                    public void onError(Throwable throwable, boolean b) {

                    }

                    @Override
                    public void onCancelled(CancelledException e) {

                    }

                    @Override
                    public void onFinished() {

                    }
                }
        );
    }

    //选项卡对应的Adaper
    class tabAdapter extends BaseAdapter {
        public int getCount() {
            return list_tab.size();
        }

        public Object getItem(int position) {
            return list_tab.get(position);
        }

        public long getItemId(int position) {
            return 0;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            final ViewHolder viewHolder;
            if (convertView == null) {
                convertView = LayoutInflater.from(CityMyDetails.this).inflate(R.layout.tab, null);
                viewHolder = new ViewHolder();
                viewHolder.tv = (TextView) convertView.findViewById(R.id.tv);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.tv.setText((String) list_tab.get(position).get("tabs"));
            return convertView;
        }

        class ViewHolder {
            public TextView tv;
        }
    }
}